#ifndef GNFILE_H
#define GNFILE_H
#include "GnMemoryObject.h"

class GNSYSTEM_ENTRY GnFile : public GnMemoryObject
{
public:
	enum OpenMode
	{
		READ_BIANRY,
		WRITE_BIANRY,
		APPEND_BIANRY,
		READ_ACSII,
		WRITE_ACSII,
		APPEND_ACSII,
		NUM_OPENMODE,
	};

public:
	typedef GnFile* (FileCreateFunc)(gtchar *fileName,
		OpenMode openMode, gtuint bufferSize);

public:
	virtual ~GnFile(void);
	static GnFile* GetFile( gtchar* fileName, OpenMode openMode, gtuint bufferSize = 20480 );
	inline static bool IsExistFile( gtchar* fileName );

	virtual gsize ReadBinary( void* pBuffer, gsize size );
	virtual gsize WriteBinary( const void * pBuffer, gsize size );
	virtual gint ReadAscii( const gtchar* format, va_list& arg );
	virtual gint WriteAscii( const gtchar* format, va_list& arg );

protected:
	GnFile( gtchar* fileName, OpenMode openMode, gtuint bufferSize = 20480 );

private:
	GNFORCEINLINE void FileOpen( gtchar* fileName, gtchar* openMode );
	GNFORCEINLINE void FileClose();

private:
	FILE* mFile;

protected:
	bool mIsBinary;
	OpenMode mOpenMode;
	guint mBufferSize;
	static FileCreateFunc* msBinaryFileCreateFunc;
	static FileCreateFunc* msAsciiFileCreateFunc;
};

#include "GnFile.inl"
#endif // GNFILE_H
